package com.scm.util;

import java.sql.*;

public class DbUtil {
	/**
	 * 加载驱动
	 */
	static{
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			System.out.println("�Ҳ������ݿ�����");
		}
	}
	
	/**
	 * 连接数据库
	 * @return
	 * @throws SQLException
	 */
	public static Connection getConn() throws SQLException{
		return DriverManager.getConnection("jdbc:mysql://localhost:3306/db_database01?useSSL=false","root","surrik");
	}
	
	/**
	 * 关闭数据库连接
	 * @param rs
	 * @param ps
	 * @param conn
	 */
	public static void close(Connection conn,ResultSet rs,Statement ps){
		try {
			if(rs != null){rs.close();}
			if(ps != null){ps.close();}
			if(conn != null){conn.close();}
		} catch (SQLException e) {
			System.out.println("关闭数据库连接异常");
		}
		
	}
	
}
